#!/bin/bash

# bash aliases

alias ls='dir --color=auto' \
  ll='ls -lhL'  \
  lsa='ls -a' \
  lla='ll -a'
alias grep='grep --color=auto'
alias curl='curl -s'
alias pj='projects'

# functions

# show informacion about the current directory
dirinfo ()
{
  printf "$(tput setaf 6)$(basename $PWD)$(tput sgr0):\n"
  /bin/ls --group-directories-first --color=auto -w 80 -FAXC
  printf "\n"
  git log -0 2>&- && {
    printf "$(tput setaf 6)Upstream URL$(tput sgr0): "
      git remote get-url origin
      git log --decorate=no -n 1
    }
  printf "\n$(tput setaf 6)Total files$(tput sgr0): $(/bin/ls -lA | wc -l)\n"
}

# make directory and cd into it
mkcd ()
{
  mkdir $1
  cd $1
}

# extract anything without remembering every command
extract () {
  if [ -f $1 ] ; then
    case $1 in
      *.tar.bz2)   tar xjf $1     ;;
      *.tar.gz)    tar xzf $1     ;;
      *.bz2)       bunzip2 $1     ;;
      *.rar)       rar x $1       ;;
      *.gz)        gunzip $1      ;;
      *.tar)       tar xf $1      ;;
      *.tbz2)      tar xjf $1     ;;
      *.tgz)       tar xzf $1     ;;
      *.zip)       unzip $1       ;;
      *.Z)         uncompress $1  ;;
      *.7z)        7z x $1    ;;
      *)           echo "'$1' cannot be extracted via extract()" ;;
    esac
  else
    echo "'$1' is not a valid file"
  fi
}

# go to projects folder
PROJECTS_FOLDER="$HOME/Work"
projects ()
{
  cd $PROJECTS_FOLDER
  dirinfo
}
